﻿using ViewMaker.Core.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.ComponentModel.Composition;

namespace ViewMaker.Core.Tests
{
    [TestClass()]
    public class ServiceLocatorTest
    {
        [Export(typeof(ITestService))]
        public class TestService : ITestService
        {
            public string Hello(string input)
            {
                return "Hello " + input;
            }
        }

        public interface ITestService
        {
            string Hello(string input);
        }

        [TestMethod()]
        public void サービスの追加と除去()
        {
            try
            {
                ServiceLocator.AddService(typeof(TestService));
                var s = ServiceLocator.GetService<ITestService>();
                Assert.AreEqual("Hello World", s.Hello("World"));
            }
            finally
            {
                ServiceLocator.RemoveService(typeof(TestService));
            }
            var nullSvc = ServiceLocator.GetService<ITestService>();
            Assert.IsNull(nullSvc);
        }
    }
}
